<html>
<head><meta charset="utf-8"><title>textDocument/rename response · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html">textDocument/rename response</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="200947801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200947801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200947801">(Jun 15 2020 at 21:24)</a>:</h4>
<p>Hi! I noticed that the response that comes back from rust-analyzer when issuing a textDocument/rename on a document that needs N edits in it is a list of N <code>TextDocumentEdit</code>s with a single <code>TextEdit</code> in it.</p>
<blockquote>
<p>A TextDocumentEdit describes all changes on a version Si and after they are applied move the document to version Si+1. So the creator of a TextDocumentEdit doesn’t need to sort the array of edits or do any kind of ordering</p>
</blockquote>
<p>The LSP specification there implies to me that applying a <code>TextDocumentEdit</code> "changes" the version of the document, so applying subsequent <code>TextDocumentEdit</code>s on it without going back to the server is potentially invalid. This is in fact an issue right now in LanguageClient-neovim, and I suppose we could solve it by grouping the edits by the text document's uri, but I feel like that is not the way it's intended to be used. </p>
<p>Is there any reason that that is not a single <code>TextDocumentEdit</code> with N <code>TextEdit</code>s instead of the current response?</p>
<p>(btw, I can open an issue, just wanted to check if there's some reason that I'm missing for it to reply in that way)</p>



<a name="200949196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200949196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200949196">(Jun 15 2020 at 21:37)</a>:</h4>
<p>I think that's just the way it's currently implemented. I don't think we check <code>workspace.workspaceEdit.documentChanges</code> either</p>



<a name="200949458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200949458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200949458">(Jun 15 2020 at 21:40)</a>:</h4>
<p>Not sure what you mean by <code>check</code> there, but it seems like VSCode handles this rename correctly, so I suspect there is some additional handling of the results there. I haven't checked this myself though, I just have checked the vim side of this, but the person who raised this issue claims it works in VSCode with the rust-analyzer extension.</p>
<p>In any case, do you think is something that needs fixing then? Should I open an issue about it?</p>



<a name="200949515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200949515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200949515">(Jun 15 2020 at 21:40)</a>:</h4>
<p>I'm going off this here: <a href="https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#workspaceEdit">https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#workspaceEdit</a></p>



<a name="200949865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200949865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200949865">(Jun 15 2020 at 21:44)</a>:</h4>
<p>I'm wondering if  this affects "undo" behavior. Are you seeing any weirdness? It may be worth filing an issue as it sounds like suboptimal behavior</p>



<a name="200949945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200949945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200949945">(Jun 15 2020 at 21:44)</a>:</h4>
<p>It kinda does yeah. To undo a rename in vim you have to press <code>u</code> once for each change in the document, whereas in other servers you just press it once and it rolls back that rename.</p>



<a name="200950086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200950086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200950086">(Jun 15 2020 at 21:46)</a>:</h4>
<p>But more importantly, it's messing up the edits themselves when there are two edits in the same line, because if the leftmost edit is applied first then the range for the rightmost one is incorrect.</p>



<a name="200950183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200950183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200950183">(Jun 15 2020 at 21:47)</a>:</h4>
<p>LanguageClient-neovim handles this when there are multiple edits in a single TextDocumentEdit by sorting the edits in a document by character, and applying them from right to left. But it can't be done as it is now because there's effectively a single edit for each TextDocumentEdit.</p>



<a name="200951239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200951239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200951239">(Jun 15 2020 at 21:58)</a>:</h4>
<p>filed <a href="https://github.com/rust-analyzer/rust-analyzer/issues/4901">https://github.com/rust-analyzer/rust-analyzer/issues/4901</a></p>



<a name="200951319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/200951319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Martin Asquino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#200951319">(Jun 15 2020 at 21:59)</a>:</h4>
<p>Btw, forgive me if any of that comes as a criticism, my english sometimes fails in correctness, but I have nothing but admiration for the work you folks are doing with rust-analyzer. <span aria-label="bow" class="emoji emoji-1f647" role="img" title="bow">:bow:</span></p>



<a name="201030160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/textDocument/rename%20response/near/201030160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/textDocument.2Frename.20response.html#201030160">(Jun 16 2020 at 15:14)</a>:</h4>
<p>Good catch! thanks for filing the issue :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>